home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-16 | 6.0 KB | 249 lines | [TEXT/MPS ] |
- {
-
- }
-
- PROGRAM TimeBaseSimple;
- { Shows basics about time bases. }
-
- USES
- MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, Traps, GestaltEqu,
- Movies, QuickTimeComponents, Strings;
-
- CONST rWindID = 128;
- rRCTID = 128;
- lastControl = 133;
- arrowsID = 133;
- rectsCount = 14;
-
- TYPE BooleanPtr = ^Boolean;
-
- TBState = RECORD
- tBase: TimeBase;
- flags: LONGINT;
- moovScale: TimeScale;
- rate: Fixed;
- prefRate: Fixed;
- startTime: TimeRecord;
- stopTime: TimeRecord;
- zeroTime: TimeRecord;
- currTime: TimeRecord;
- duration: TimeValue;
- clockName: Str255;
- END;
-
- RectsRecHandle = ^RectsRecPtr;
-
- RectsRecPtr = ^RectsRec;
-
- RectsRec = RECORD
- rectCount: Integer;
- rects: ARRAY [0..rectsCount] OF Rect;
- END;
-
-
- VAR gMCPlay: MovieController;
- gWind: WindowPtr;
- gMoov: Movie;
- gSystemVersion: Integer;
- gDoneFlag: Boolean;
-
- gErr: OSErr;
- gResult: Boolean;
- gEventRec: EventRecord;
- gMoovBox: Rect;
-
- gLooping: Boolean;
- gShuttle: ControlHandle;
- gTBState: TBState;
- tr: TimeRecord;
- r: Rect;
- gArrows: PicHandle;
-
- {$I TimeBaseSimpleAux.p} { Includes all auxiliary routines. }
-
-
- FUNCTION GetMovie: Movie;
- {
-
- purpose promp the user to select a file and then get a movie out of it
- }
-
- VAR reply: StandardFileReply;
- where: Point;
- localMoov: Movie;
- err: OSErr;
- movieResFile,
- resID: Integer;
- wasChanged: Boolean;
- moovResName: Str255;
-
- BEGIN
- err := fnfErr; { This is as good an error as any other }
- IF DisplayGetFile('Please select movie file:',reply) THEN
- BEGIN
- err := OpenMovieFile(reply.sfFile, movieResFile, fsRdPerm);
- IF err = noErr THEN
- resID := 0; { First 'moov' found }
- err := NewMovieFromFile( localMoov, movieResFile, resID, moovResName, newMovieActive, wasChanged);
- IF CloseMovieFile(movieResFile) <> noErr THEN
- ErrorControl('Could not close the file');
- END;
- IF err = noErr THEN
- GetMovie := localMoov
- ELSE
- GetMovie := nil;
- END;
-
-
- PROCEDURE SetUpControls(wind: WindowPtr);
- VAR c: ControlHandle;
-
- BEGIN
- gShuttle := GetNewControl(rWindID, gWind);
- c := GetNewControl(rWindID+1, gWind);
- c := GetNewControl(rWindID+2, gWind);
- c := GetNewControl(rWindID+3, gWind);
- c := GetNewControl(rWindID+4, gWind);
- c := GetNewControl(rWindID+5, gWind);
- END;
-
- FUNCTION SetUpMovie(moov: Movie; wind: WindowPtr; VAR mcPlay: MovieController): OSErr;
- {
-
- purpose given a window and a movie this routine sizes the
- window to fit the movie, gets the movie player by
- calling NewMovieController.
- }
-
- VAR
- err: OSErr;
- moovBox,
- controllerBox: Rect;
- m: Movie;
-
- BEGIN
-
- GetMovieBox(moov, moovBox);
-
- IF (((moovBox.right - moovBox.left) <= (gMoovBox.right - gMoovBox.left))
- AND ((moovBox.bottom - moovBox.top) <= (gMoovBox.bottom - gMoovBox.top))) THEN
- BEGIN
- OffsetRect(moovBox, -(moovBox.left+gMoovBox.left), -(moovBox.top+gMoovBox.top));
- SetMovieBox(moov, moovBox);
- END
- ELSE
- BEGIN
- SetMovieBox(moov, gMoovBox);
- END;
-
- mcPlay := NewMovieController( moov, gMoovBox, mcTopLeftMovie);
-
- IF mcPlay = NIL THEN { Could not get controller pass back some error }
- BEGIN
- err := internalQuickTimeError; { a.k.a. whatever error message }
- ErrorControl('Could not get controller for movie with MCNewMovieController');
- END;
-
- err := MCEnableEditing(mcPlay, TRUE);
- err := MCDoAction(mcPlay, mcActionSetPlaySelection, Ptr(1));
-
- SetUpMovie := err;
- END;
-
- (* There are some parameters that change on the fly and we need to
- check them up every time we go through the event loop. The parameters
- are:
- shuttle position - shuttle need to rotate with the movie
- rate - rate changes when movie is looping
- duration - when a selection is made duration changes when playing.
- note that while not playing the duration is set to the
- whole movie to allow new selection
- *)
- PROCEDURE UpdateParams;
- VAR startTimeValue,
- stopTimeValue: TimeValue;
- duration: LONGINT;
- aFix: Fixed;
- r: Rect;
-
- BEGIN
- CallSetCtlValueNoProc(gShuttle, GetTimeBaseTime(gTBState.tBase, gTBState.moovScale, tr) DIV 10);
- aFix := GetMovieRate(gMoov);
- IF aFix <> gTBState.rate THEN
- BEGIN
- GetIndRect(rRCTID, 5, r);
- InvalRect(r);
- gTBState.rate := aFix;
- END;
- startTimeValue := GetTimeBaseStartTime(gTBState.tBase, gTBState.moovScale, gTBState.startTime);
- stopTimeValue := GetTimeBaseStopTime(gTBState.tBase, gTBState.moovScale, gTBState.stopTime);
- duration := stopTimeValue - startTimeValue;
- IF duration <> gTBState.duration THEN
- BEGIN
- GetIndRect(rRCTID, 1, r);
- InvalRect(r);
- gTBState.duration := duration;
-
- GetIndRect(rRCTID, 10, r);
- InvalRect(r);
-
- GetIndRect(rRCTID, 12, r);
- InvalRect(r);
- END;
-
- END;
-
- BEGIN (* MCSample *)
-
- IF InitSystem <> noErr THEN { Initialize all managers }
- BEGIN
- ErrorControl('Initialization failed');
- Exit(PROGRAM);
- END;
-
- gWind := GetNewCWindow(rWindID,NIL, WindowPtr(-1));
-
- SetUpControls(gWind);
-
- SetPort(gWind); { Make our window the current port }
-
- REPEAT
- BEGIN
- InitVars;
- gMoov := GetMovie; { ask user to select a movie file }
-
- IF gMoov = nil THEN
- BEGIN
- { ErrorControl('Could not get the movie!;g'); }
- LEAVE
- END
- ELSE { if we have a movie then continue }
- BEGIN
- InitControls(gMoov, gWind);
- InvalRect(gWind^.portRect);
- gErr := SetUpMovie(gMoov,gWind,gMCPlay);
- IF gErr <> noErr THEN
- ErrorControl('Error at SetUpMovie')
- ELSE
- BEGIN
- WHILE NOT gDoneFlag DO
- BEGIN
- gResult := GetNextEvent(everyEvent, gEventRec);
- (* gResult := WaitNextEvent(everyEvent, gEventRec, 30, nil); *)
-
- IF ( MCIsPlayerEvent(gMCPlay, gEventRec) = 0 ) THEN
- BEGIN
- UpdateParams; { check for changes }
- IF gResult THEN { Player didn't handle the event }
- HandleEvent(gEventRec); { Cliks in go away terminate app }
- END
- END;
- gErr := CloseComponent(gMCPlay);
- END;
- DisposeMovie(gMoov);
- END
- END
- UNTIL FALSE;
- DisposeWindow(gWind);
- ExitMovies;
- END.